const { backendApiUrl } = require('../../utils/config');
const { apiRequest } = require('../_utils/apiRequest');
/**
 * 获取用户订单列表
 * @param {string} userId - 用户 ID
 * @returns {Promise} - 返回订单列表的 Promise
 */
export const fetchOrderList = (userId, status) => {
  if (!userId) {
    return Promise.reject(new Error('用户未登录或未获取到用户信息'));
  }

  const requestData = status !== '全部' ? { status } : {}; // 只有非“全部”才传递 status

  return apiRequest({
    url: `${backendApiUrl}/orders/me`,
    method: 'GET',
    data: requestData
  });
};

module.exports = {
  fetchOrderList
};
